package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.domain.DataResult;
import com.dongdongshop.em.DataResultEnum;
import com.dongdongshop.pojo.TbItemCat;
import com.dongdongshop.service.TbItemCatService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("TbItemCatController")
public class TbItemCatController {

    @Reference
    private TbItemCatService tbItemCatService;


    @RequestMapping("ToTbItemCatShow")
    public String ToTbItemCatShow(){

        return "admin/item_cat";
    }

    @ResponseBody
    @RequestMapping("select")
    public DataResult select(@RequestParam(required = false,defaultValue = "0")Long id){
        List<TbItemCat> tbItemCats = tbItemCatService.selectById(id);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(tbItemCats);
    }
    @RequestMapping("toAdd")
    @ResponseBody
    public Boolean toAdd(TbItemCat tbItemCat){
        Boolean b = tbItemCatService.insert(tbItemCat);
        return b ;
    }

    @ResponseBody
    @RequestMapping("updata")
    public DataResult updata(Long id){
        TbItemCat updata = tbItemCatService.updata(id);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(updata);
    }

    @ResponseBody
    @RequestMapping("updatas")
    public Boolean updatas(TbItemCat tbItemCat){
        Boolean b = tbItemCatService.updates(tbItemCat);
        return b;
    }

    @ResponseBody
    @RequestMapping("deleteItemType")
    public Boolean delete(@RequestParam("ids[]") Long[] ids){
        Boolean b =tbItemCatService.deleteByid(ids);
        return b;
    }
}
